namespace SqlQueryBuilder.Criterias
{
    /// <summary>
    /// From Criteria
    /// </summary>
    public class From : ICriteria
    {
        #region Properties

        /// <summary>
        /// Gets or sets from clause.
        /// </summary>
        /// <value>From clause.</value>
        public string FromClause { get; set; }
        
        /// <summary>
        /// Gets or sets the alias.
        /// </summary>
        /// <value>The alias.</value>
        public string Alias { get; set; }

        #endregion

        /// <summary>
        /// Initializes a new instance of the <see cref="From"/> class.
        /// </summary>
        /// <param name="fromClause">From clause.</param>
        /// <param name="alias">The alias.</param>
        public From(string fromClause, string alias)
        {
            FromClause = fromClause;
            Alias = alias;
        }

        /// <summary>
        /// Builds the criteria.
        /// </summary>
        /// <returns></returns>
        public string BuildCriteria()
        {
            return (string.IsNullOrEmpty(Alias))
                       ? string.Format("FROM {0} ", FromClause)
                       : string.Format("FROM {0} {1} ", FromClause, Alias);
        }
    }
}